/*
 * @Author: tcosfish
 * @Date: 2022-08-18 15:08:26
 * @LastEditors: tcosfish
 * @LastEditTime: 2022-08-18 15:25:22
 * @FilePath: \loadFile\src\utils\getLocalIP.ts
 */

import { networkInterfaces } from "os"

function getLocalIP() {
  const netDict = networkInterfaces()
  for (const devName in netDict) {
    const netList = netDict[devName]
    if (netList) {
      for (const net of netList) {
        const { address, family, internal } = net
        if (address !== "127.0.0.1" && family === "IPv4" && !internal) {
          console.log(address)
          return address
        }
      }
    }
  }
}

export { getLocalIP }
